'''
手机按键的字母组合
https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/
'''
from collections import defaultdict
def func(string):
    NumList = [str(i) for i in range(2,10)]
    d = defaultdict(list)
    AlphaList = [ chr(i) for i in range(97,123)]
    index = 0
    def create_graph(n,str):
        nonlocal index
        for j in range(n):
            d[i].append(str[index + j])
        else:
            index += n
    for i in NumList:
        if i=="7" or i=="9":
            create_graph(4,AlphaList)
        else:
            create_graph(3,AlphaList)
    #上面的这些代码直接使用dict应该好做一点，写成上面这样是为了跟多的使用一些函数或知识点
    res = []
    def dfs(str,index):
        if len(res) == len(str):
            print("".join(res))
            return
        for i in d[str[index]]:
            res.append(i)
            dfs(str,index+1)
            res.pop()
    dfs(string,0)

if __name__ == '__main__':
    func("23")
    '''
    ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
    '''
